package sz.szsmk.citizencard.ui.newversion.activity.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.youth.banner.adapter.BannerAdapter
import sz.szsmk.citizencard.model.network.clarkbean.response.AdInfo
import sz.szsmk.citizencard.ui.adapter.ViewHolder

/**
 *  author : hyt
 *  date : 2020/10/27
 *  description :
 */
class HomeBannerAdapter(var context: Context,datas: List<AdInfo?>?) : BannerAdapter<AdInfo?, HomeBannerAdapter.BannerViewHolder?>(datas) {
    override fun onCreateHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {
        val imageView = ImageView(parent.context)
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.layoutParams = ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT)
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        return BannerViewHolder(parent.context, imageView, imageView)
    }


    inner class BannerViewHolder(context: Context?, itemView: View?, var iv: ImageView) : ViewHolder(context, itemView)

    override fun onBindView(holder: BannerViewHolder?, data: AdInfo?, position: Int, size: Int) {
        Glide.with(context).load(data?.resource_url)
                .into(holder?.iv)
    }
}